from multiprocessing import Manager
from tortoise import Model, fields
from enum import Enum, unique
from .mixin import DictMixin


@unique
class RoleEnum(Enum):
    SUPER_ADMIN = 'superAdmin'
    S_ADMIN = 's_admin'
    STU = 'stu'


class GenderEnum(Enum):
    MAN = '男'
    WOMEN = '女'
    UNKNOWN = '未知'


class User(DictMixin, Model):
    id = fields.IntField(pk=True)  # int not null primary key,
    username = fields.CharField(255)  # varchar(255)  null comment '登录用户名',
    password = fields.CharField(255)  # varchar(255)  null comment '登录密码',
    # varchar(255)  null comment 'pc端登录checkmd5',
    pc_login_check = fields.CharField(255)
    pc_login_at = fields.DatetimeField()  # datetime      null comment 'pc端最后登录时间',
    # varchar(32)   null comment '账号类型：学生，教师，监察，备用，管理员',
    role = fields.CharEnumField(enum_type=RoleEnum, description=[
                                'superAdmin', 's_admin', 'stu'])
    desc = fields.CharField(1024)  # varchar(1024) null comment '个人描述',
    team_id = fields.IntField()  # int           null comment 'team表的id，表明该账户所属的team',
    real_name = fields.CharField(255)  # varchar(255)  null comment '真实姓名',
    # varchar(32)   null comment '性别',
    gender = fields.CharEnumField(
        enum_type=GenderEnum, description=['男', '女', '未知'])
    identity = fields.CharField(255)  # varchar(255)  null comment '身份证号',
    sno = fields.CharField(255)  # varchar(255)  null comment '学号',
    exam_no = fields.CharField(255)  # varchar(255)  准考证号,
    exam_location = fields.CharField(255)  # varchar(255)  null comment '考试地点',
    user_class = fields.CharField(255)  # varchar(255)  null comment '学生班级',
    birthday = fields.DatetimeField()  # datetime      null comment '出生年月日',
    phone_num = fields.CharField(32)  # varchar(32)   null comment '联系电话',
    mail = fields.CharField(255)  # varchar(255)  null comment '邮箱',
    QQ = fields.CharField(255)  # varchar(255)  null comment 'QQ',
    weChat = fields.CharField(255)  # varchar(255)  null comment '微信号',
    address = fields.CharField(255)  # varchar(255)  null comment '地址',
    academy = fields.CharField(255)  # varchar(255)  null,
    ip = fields.CharField(255)  # varchar(255)  null,
    sign = fields.CharField(255)  # varchar(255)  null,
    photo_url = fields.CharField(255)  # varchar(255)  null comment '头像地址',
    create_at = fields.DatetimeField()  # datetime      null comment '创建时间',
    # varchar(255)  null comment '邀请码,md5,每次生成',
    invite_chars = fields.CharField(255)
    version = fields.IntField()  # int           null

    class Meta:
        table = 'user'
